﻿using System.Collections.Generic;

namespace Core
{
    /// <summary>
    /// 对话系统
    /// </summary>
    public class DialogueSystem : Core.Component, IAwake<int>
    {
        public int WndID { get; private set; }

        private IDialogueWnd window;

        private readonly Queue<string> messages = new();

        public void Awake(int wndID)
        {
            WndID = wndID;
            window = G.UI.Get(wndID) as IDialogueWnd;

            if (window == null)
            {
                log.err($"DialogueSystem.Awake Error, IDialogueWnd不存在");
            }

            messages.Clear();
        }

        public override void Dispose()
        {
            if (IsDisposed) return;
            base.Dispose();
        }

        public int Count => messages.Count;

        /// <summary>
        /// 状态
        /// 0，没有消息需要处理，且DialogueWnd界面处于关闭状态
        /// 1，有消息在队列种需要处理，但界面还未打开
        /// 2，正在处理消息，界面处于打开状态
        /// </summary>
        public int State { get; private set; }

        public void SetState(int state)
        {
            State = state;
        }
        public string Pop()
        {
            return messages.Dequeue();
        }

        public void Push(string message)
        {
            if (State == 0)
            {
                SetState(1);
            }

            messages.Enqueue(message);
            G.UI.Show(WndID);
        }
    }
}
